﻿
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using Utils;
using PanasonicWarranty.DAL;
namespace PanasonicWarranty.Business
{
    public partial class SysUserGroup
    {
    	#region public properties
		[Required(ErrorMessage="UserID Required")]
		public int UserID { get; set; }
		[Required(ErrorMessage="GroupID Required")]
		public int GroupID { get; set; }
		#endregion

		#region constructor
		public SysUserGroup(){ }

		public SysUserGroup(IDataReader rd)
		{
			this.UserID = (int)rd["UserID"];
			this.GroupID = (int)rd["GroupID"];
		}
		#endregion

		#region private method
        private bool Create()
        {
            return DBSysUserGroup.Create(UserID, GroupID);
        }

        private bool Update()
        {
            return DBSysUserGroup.Update(UserID, GroupID);
        }
		#endregion

		#region public method
		public bool Save()
		{
            if(UserID != 0)
            {
                return Update();
            }
            else
            {
                return Create();
            }

            if(GroupID != 0)
            {
                return Update();
            }
            else
            {
                return Create();
            }
		}
		#endregion

		#region static method
        public static bool Delete(int UserID, int GroupID)
        {
            return DBSysUserGroup.Delete(UserID, GroupID);
        }

        public static List<SysUserGroup> GetAll()
        {
            return ObjectClass.CreateList<SysUserGroup>(DBSysUserGroup.GetAll());
        }

        public static SysUserGroup GetByKey(int UserID, int GroupID)
        {
            return ObjectClass.CreateInstance<SysUserGroup>(DBSysUserGroup.GetByKey(UserID, GroupID));
        }

        public static List<SysUserGroup> GetByForeignKeys(int UserID, int GroupID)
        {
            return ObjectClass.CreateList<SysUserGroup>(DBSysUserGroup.GetByForeignKeys(UserID, GroupID));
        }

        public static List<SysUserGroup> GetByTop(string top, string where, string order)
        {
            return ObjectClass.CreateList<SysUserGroup>(DBSysUserGroup.GetByTop(top, where, order));
        }
		#endregion
	}
}
